package com.qst.itoffer.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.qst.itoffer.dao.ApplicantDao;

/**
 * Servlet implementation class ApplicantRegisterServlet
 * 求职者注册业务处理
 */
@WebServlet("/ApplicantRegisterServlet")
public class ApplicantRegisterServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ApplicantRegisterServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		//设置请求和响应编码
		request.setCharacterEncoding("UTF-8");
		response.setContentType("text/html;charset=UTF-8");
		PrintWriter out = response.getWriter();
		
		//获取请求参数
		String email= request.getParameter("email");
		String pawd = request.getParameter("pawd");
		
		//邮箱唯一性验证：注册使用的邮箱不能重复
		ApplicantDao appDao = new ApplicantDao();
		Boolean flag = appDao.isExistEmail(email);
		if(flag) {
			out.println("<script type='text/javascript'>");
			out.println("alert('邮箱已被注册，请重新输入！');");
			out.println("window.location = 'register.jsp' ");
			out.println("</script >");
		}else {
			appDao.insertEmail(email,pawd);
			response.sendRedirect("regsuccess.jsp");
		}
		
	}

}
